package com.alliance.shuwei.entity;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

@Entity
@Table(name = "category")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class Category extends Auditable {
	@Id
	@GeneratedValue
	@Column(name = "category_id")
	private Integer id;
	private String name;
	private Boolean display;
	@ManyToOne
	@JoinColumn(name = "parent_category_id", nullable = true)
	private Category parentCategory;
	@OneToMany(mappedBy = "parentCategory")
	private List<Category> childCategories;
	@ManyToMany(mappedBy = "categories")
	private List<ResourceProvider> resourceProviders;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	@JsonProperty("name")
	public void setName(String name) {
		this.name = name;
	}

	public Boolean getDisplay() {
		return display;
	}

	@JsonProperty("display")
	public void setDisplay(Boolean display) {
		this.display = display;
	}

	public Category getParentCategory() {
		return parentCategory;
	}

	@JsonProperty("parent_category")
	public void setParentCategory(Category parentCategory) {
		this.parentCategory = parentCategory;
	}

	@JsonProperty("child_categories")
	public List<Category> getChildCategories() {
		return childCategories;
	}

	public void setChildCategories(List<Category> childCategories) {
		this.childCategories = childCategories;
	}

	@JsonIgnore
	public List<ResourceProvider> getResourceProviders() {
		return resourceProviders;
	}
}
